<?php

class Username {
	const min_chars = 3;
	const max_chars = 12;
    
	
	/**
	 * @var string
	 */
	private $username = "";
	
	/**
	 * @param string $string
	 */
	public function __construct($string) {
		if ($this->isUsernameOk($string)) {
			$this->username = $string;
		}
	}
	
	/**
	 * @return string
	 */
	public function __toString() {
		return $this->username;
	}
	
	/**
	 * @param @string
	 * @return boolean
	 */
	public function isUsernameOk($string) {
		if (false) {
			throw new \Exception("Username contains invalid characters.");
		}	
		else if (strlen($string) < self::min_chars) {
			throw new \Exception("Username is too short (min ".self::min_chars." characters).");
		} 
		else if (strlen($string) > self::max_chars) {
			throw new \Exception("Username is too long (max ".self::max_chars." characters).");
		}
		return true;
	}
}
